package com.readbook.action;


import com.readbook.service.SjflService;
import com.readbook.util.MD5;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/sjfl")
public class sjfl {
    @Resource
    private SjflService sjflService;


    @RequestMapping("Search_bookclass.html")
    @ResponseBody
    public Map<String, Object> Search_bookclass(HttpServletRequest request, HttpServletResponse response) {
        String classname = "";
        if (request.getParameter("classname") != null) {
            classname = request.getParameter("classname").toString().trim();
        }

        Map<String, Object> gmap = new HashMap<String, Object>();
        gmap.put("classname", classname);

        List<Map<String, Object>> list1 = sjflService.Search_bookclass(gmap);
        Map<String, Object> rmap = new HashMap<String, Object>();
        rmap.put("data", list1);
        return rmap;
    }

    @RequestMapping("getPidClass.html")
    @ResponseBody
    public List<Map<String, Object>> getPidClass(HttpServletRequest request, HttpServletResponse response) {
        List<Map<String, Object>> list1 = sjflService.getPidClass();
        return list1;
    }


    @RequestMapping("del_bookclass.html")
    @ResponseBody
    public Map<String, Object> del_bookclass(HttpServletRequest request, HttpServletResponse response) {
        String classid = request.getParameter("classid").trim();
        Map<String, Object> gmap = new HashMap<String, Object>();
        gmap.put("classid", classid);
        Map<String, Object> getm = sjflService.del_bookclass(gmap);
        return getm;
    }


    /**
     * @author 牟明艳
     * @comments 书籍分类添加
     * @time 2019年7月26日14:35:43
     */
    @RequestMapping("InsertBookclass.html")
    public @ResponseBody
    Map<String, Object> InsertBookclass(HttpServletRequest req) throws Exception {
        Map<String, Object> gmap = new HashMap<String, Object>();
        String classid = UUID.randomUUID().toString().replaceAll("-", "");
        gmap.put("classid", classid);

        String classname = req.getParameter("classname").trim();
        gmap.put("classname", classname);

        String pid = "";
        if (req.getParameter("pid") != null) {
            pid = req.getParameter("pid").toString().trim();
        }
        gmap.put("pid", pid);

        Map<String, Object> rmap = new HashMap<String, Object>();
        int m = sjflService.InsertBookclass(gmap);
        if (m > 0) {
            rmap.put("result", false);
            rmap.put("msg", "添加失败,请联系管理员");
            return rmap;
        }
        rmap.put("result", false);
        rmap.put("msg", "保存成功!");
        return rmap;
    }


    /**
     * @author 牟明艳
     * @comments 书籍分类修改
     * @time 2019年8月2日10:07:13
     */
    @RequestMapping("EditBookclass.html")
    public @ResponseBody
    Map<String, Object> EditBookclass(HttpServletRequest req) throws Exception {
        Map<String, Object> gmap = new HashMap<String, Object>();
        String classid = req.getParameter("classid");
        gmap.put("classid", classid);

        String pid = "";
        if (req.getParameter("pid") != null) {
            pid = req.getParameter("pid").toString().trim();
        }
        gmap.put("pid", pid);

        String classname = "";
        if (req.getParameter("classname") != null) {
            classname = req.getParameter("classname").toString().trim();
        }
        gmap.put("classname", classname);

        Map<String, Object> rmap = new HashMap<String, Object>();
        int m = sjflService.EditBookclass(gmap);
        if (m > 0) {
            rmap.put("result", false);
            rmap.put("msg", "修改失败,请联系管理员");
            return rmap;
        }
        rmap.put("result", false);
        rmap.put("msg", "保存成功!");
        return rmap;
    }


}
